//
//  IFTemplateManagerCell.m
//  Medicare
//
//  Created by admin on 2017/7/6.
//  Copyright © 2017年 medicare. All rights reserved.
//

#import "IFTemplateManagerCell.h"
#import "LongPressFactory.h"
#import "IFMySchedulingPublicDefines.h"

@interface IFTemplateManagerCell ()<ZLongPressClickDelegate>

@end

@implementation IFTemplateManagerCell

- (void)awakeFromNib {
    [super awakeFromNib];
    UILongPressGestureRecognizer *presss = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longClick:)];
    [self addGestureRecognizer:presss];
    self.stateBtn.selected = NO;
    [self.stateBtn setImage:[UIImage imageNamed:@"document_consulationRadioButtonUnselected"] forState:UIControlStateNormal];
    [self.stateBtn setImage:[UIImage imageNamed:@"document_consulationRadioButtonSelected"] forState:UIControlStateSelected];
    
    
}

- (void)longClick:(UILongPressGestureRecognizer *)longRecognizer {
    
    if (longRecognizer.state==UIGestureRecognizerStateBegan) {
        [self becomeFirstResponder];
        if (![self.subviews.lastObject isKindOfClass:[LongPressView class]]) {
            LongPressView *longPress = [[LongPressFactory shareManager] createLongPress];
            longPress.frame =CGRectMake(0, 0, kScreenWidth, CGRectGetHeight(self.frame));
            longPress.titleArray = @[@"批量\n删除",@"删除"];
            longPress.delegate = self;

            longPress.customColorArray = @[[UIColor colorWithHexString:@"e49518"],[UIColor colorWithHexString:@"eb2323"]];
            if (self.isAddGes) {
                
            } else {
            [self addSubview:longPress];
            }
            [longPress show];
        }
    }
    
    
}

- (IBAction)stateBtnClick:(id)sender {
    if (self.selectTemplateManagerBlock) {
        self.selectTemplateManagerBlock(sender);
    }
    
}



#pragma mark 处理action事件
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender{
    if(action ==@selector(deleteClicked:)){
        return YES;
    }
    return [super canPerformAction:action withSender:sender];
}
#pragma mark  实现成为第一响应者方法
- (BOOL)canBecomeFirstResponder{
    return YES;
}

- (void)deleteClicked:(UIButton *)sender {
    if (self.deleteTemplateBlock) {
        self.deleteTemplateBlock(sender);
    }
}

- (void)longPressViewButtonClick:(UIButton *)sender andLongPressView:(LongPressView *)longPress {
    if (self.deleteTemplateBlock) {
        self.deleteTemplateBlock(sender);
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
